﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DoAn_BumTruong_DesignPattern
{
    public class Facades
    {
        //Khoi thao MenuProxy
        MenuProxy _mnproxy;
        //
        //
        ArticleProxy _arproxy;
        //
        ModuleProxy _mdproxy;
        //
        CommentProxy _cmproxy;
        public Facades()
        {
            if (_mnproxy == null)
            {
                _mnproxy = new MenuProxy();
            }
            if (_mdproxy == null)
            {
                _mdproxy = new ModuleProxy();
            }
            if (_arproxy == null)
            {
                _arproxy = new ArticleProxy();
            }
            if (_cmproxy == null)
            {
                _cmproxy = new CommentProxy();
            }
        }
        //=================================Menu======================================//
        public List<Menus> MenuListAll()
        {
            return _mnproxy.ListAll();
        }
        public List<Menus> GetMenuRightTop(string menutype)
        {
            return _mnproxy.GetMenuRightTop(menutype);
        }
        public List<Menus> SelectParentID()
        {
            return _mnproxy.SelectParentID();
        }
        public List<Menus> SelectParentIDChidren()
        {
            return _mnproxy.SelectParentIDChidren();
        }
        public List<Menus> PagingMenu(string page, out int howManyPage)
        {
            return _mnproxy.Paging(page, out howManyPage);

        }
        public Menus SignleMenu(string menuID)
        {
            return _mnproxy.SingleMenu(menuID);
        }

        //Update Active
        public bool UpdateActiveMenu(int id, bool state)
        {
            if (_mnproxy == null)
                return false;
            return _mnproxy.UpdateActive(id, state);
        }

        //Update MenuType
        public bool UpdateMenuTypeMenu(int id, int type)
        {
            if (_mnproxy == null)
                return false;
            return _mnproxy.UpdateMenuType(id, type);
        }

        //Update OrderNo
        public bool UpdateOrderNoMenu(int id, int orderNo)
        {
            if (_mnproxy == null)
                return false;
            return _mnproxy.UpdateOrderNo(id, orderNo);
        }

        //Update Menu
        public bool UpdateMenu(object o)
        {
            if (_mnproxy == null)
                return false;
            return _mnproxy.Update(o);
        }

        //Add
        public bool AddMenu(object o)
        {
            if (_mnproxy == null)
                return false;
            return _mnproxy.Add(o);
        }

        //Delete
        public bool DeleteMenu(object o)
        {
            if (_mnproxy == null)
                return false;
            return _mnproxy.Delete(o);
        }

        //=================================Article====================================//
        //public Article ArticleByID(string articleID)
        //{
        //    return _arproxy.SelectByArticleID(articleID);
        //}
        public List<Articles> ArticleByID(string articleID)
        {
            return _arproxy.SelectByArticleID(articleID);
        }
        public List<Articles> PagingArticle(string page, out int howManyPage)
        {
            return _arproxy.Paging(page, out howManyPage);
        }
        public List<Articles> PagingArticleByMenu(string menuID, string page, out int howManyPage)
        {
            return _arproxy.PagingByMenuID(menuID, page, out howManyPage);
        }
        public List<Articles> SearchTitle(string title)
        {
            return _arproxy.SearchTitle(title);
        }
        public List<Articles> PagingBySearchName(string title, string page, out int howManyPage)
        {
            return _arproxy.PagingBySearchName(title, page, out howManyPage);
        }
        public bool AddArticle(Articles ar)
        {
            return _arproxy.Add(ar);
        }
        //=================================Module====================================//
        public List<Modules> ModuleListAll()
        {
            return _mdproxy.ListAll();
        }
        public List<Modules> PagingModule(string page, out int howManyPage)
        {
            return _mdproxy.Paging(page, out howManyPage);
        }
        public Modules SingleModule(string moduleID)
        {
            return _mdproxy.SingleModule(moduleID);
        }
        //Update Active
        public bool UpdateActiveModule(int id, bool state)
        {
            if (_mdproxy == null)
                return false;
            return _mdproxy.UpdateActive(id, state);
        }


        //Update Position
        public bool UpdatePositionModule(int id, int pos)
        {
            if (_mdproxy == null)
                return false;
            return _mdproxy.UpdatePosition(id, pos);
        }

        //Update OrderNo
        public bool UpdateOrderNoModule(int id, int orderNo)
        {
            if (_mdproxy == null)
                return false;
            return _mdproxy.UpdateOrderNo(id, orderNo);
        }

        //Add module
        public bool AddModule(object o)
        {
            if (_mdproxy == null)
                return false;
            return _mdproxy.Add(o);
        }

        //Update
        public bool UpdateModule(object o)
        {
            if (_mdproxy == null)
                return false;
            return _mdproxy.Update(o);
        }

        //Delete
        public bool DeleteModule(object o)
        {
            if (_mdproxy == null)
                return false;
            return _mdproxy.Delete(o);
        }

        //=================================Comment====================================//
        public List<Comments> GetCommentByArticleID(string articleID)
        {
            return _cmproxy.GetCommentByArticleID(articleID);
        }
        public bool AddComment(Comments cm)
        {
            return _cmproxy.Add(cm);
        }
        public int CountCommentByAritcleID(string articleID)
        {
            return _cmproxy.CountComementByArticleID(articleID);
        }
        public List<Comments> PagingComment(string page, out int howManyPage)
        {
            return _cmproxy.Paging(page, out howManyPage);
        }

        //Update Show/Hide
        public bool UpdateShowHide(int commentId, bool sh)
        {
            if (_cmproxy == null)
                return false;
            return _cmproxy.UpdateShowHide(commentId, sh);
        }
    }
}